import { useAuth } from '@/stores/auth'
//引入nprogress 进度条插件
import NProgress from 'nprogress'
/**
 * 设置路由守卫
 * @param router
 */
export function setRouterGuards(router: any) {
  // 全局 前置路由守卫
  router.beforeEach(async (to: any, from: any, next: any) => {
    NProgress.start()
    if (to.name !== 'login') {
      if (!useAuth().token) {
        next({
          name: 'login',
          query: {
            redirect: to.fullPath
          }
        })
      }
    }
    next()
  })
  // 全局 后置路由守卫
  router.afterEach(() => {
    NProgress.done()
  })
}
